package makovo.ajax;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import makovo.data.Items;

import org.apache.struts2.interceptor.SessionAware;

public class ServletGeoInfo extends HttpServlet implements SessionAware {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = (String) request.getParameter("m");
		String stateId = (String) request.getParameter("state");
		String res = null;

		if (method.equals("gc")) {

			res = Items.GeoInfo.getCities(Integer.valueOf(stateId));
		} else if (method.equals("gt")) {
			String cityId = (String) request.getParameter("city");
			res = Items.GeoInfo.getTowns(Integer.valueOf(stateId), Integer.valueOf(cityId));
		}

		response.getWriter().write(res);
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub

	}
}
